home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / atari / c / stik_dev / forecast / window.c < prev   
C/C++ Source or Header  |  1996-01-10  |  5KB  |  214 lines

  1. #include <aes.h>
  2. #include <vdi.h>
  3. #include <osbind.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include "forecast.h"
  7. #include "main.h"
  8.  
  9. /* Prototypes... */
  10.  
  11.     void    draw_win(void);
  12.     void    create_win(const char *);
  13.     void    open_win(void);
  14.     void    close_win(void);
  15.     void    delete_win(void);
  16.     short    do_menu(short);
  17.     short    dialog(OBJECT *, short);
  18.     void    set_button(OBJECT *, short, short);
  19.     short    get_button(OBJECT *, short);
  20.     void    empty_edits(OBJECT *tree, int object);
  21.     void     set_tedinfo(OBJECT *tree,int obj,char *source);
  22.  
  23. /* Externals... */
  24.  
  25.     extern void    new_game(void);
  26.  
  27.     extern short    endmainloop;
  28.     extern short    pause;
  29.     extern short    vdi_handle, work_out[57];
  30.     extern WINDOW    win;
  31.     extern MFDB    work, screen;
  32.     extern OBJECT    *menu_ptr, *about_ptr, *help_ptr;
  33.  
  34.     extern short    open;
  35.  
  36.     extern char out[80];
  37.     extern char city_tla[3];
  38.  
  39.  
  40. void draw_win(void)
  41.     {
  42.     short pxyarray[8];
  43.     GRECT rect, deskrect;
  44.  
  45.     wind_get(DESK, WF_WXYWH, &deskrect.g_x, &deskrect.g_y, &deskrect.g_w, &deskrect.g_h);
  46.  
  47.     wind_update(BEG_UPDATE);
  48.     wind_get(win.handle, WF_FIRSTXYWH, &rect.g_x, &rect.g_y, &rect.g_w, &rect.g_h);
  49.  
  50.     do
  51.         {
  52.         if (rc_intersect(&win.w_rect, &rect))
  53.             {
  54.             rc_intersect(&deskrect, &rect);
  55.             pxyarray[4]=rect.g_x;
  56.             pxyarray[5]=rect.g_y;
  57.             pxyarray[6]=rect.g_x+rect.g_w-1;
  58.             pxyarray[7]=rect.g_y+rect.g_h-1;
  59.             pxyarray[0]=pxyarray[4]-win.w_rect.g_x;
  60.             pxyarray[1]=pxyarray[5]-win.w_rect.g_y;
  61.             pxyarray[2]=pxyarray[6]-win.w_rect.g_x;
  62.             pxyarray[3]=pxyarray[7]-win.w_rect.g_y;
  63.             Vsync();
  64.             v_hide_c(vdi_handle);
  65.             vro_cpyfm(vdi_handle, 3, pxyarray, &work, &screen);
  66.             v_show_c(vdi_handle, 1);
  67.             }
  68.         wind_get(win.handle, WF_NEXTXYWH, &rect.g_x, &rect.g_y, &rect.g_w, &rect.g_h);
  69.         }
  70.     while (rect.g_w & rect.g_h);
  71.  
  72.     wind_info(win.handle, out);
  73.  
  74.     wind_update(END_UPDATE);
  75.     }
  76.  
  77. void create_win(const char *title)
  78.     {
  79. /*    GRECT deskrect;*/
  80.     GRECT windrect;
  81.  
  82.     wind_get(DESK, WF_WORKXYWH, &windrect.g_x, &windrect.g_y, &windrect.g_w, &windrect.g_h);
  83.  
  84. /*    wind_calc(WC_BORDER, WINTYPE, deskrect.g_x, deskrect.g_y, deskrect.g_w, deskrect.g_h,
  85.             &windrect.g_x, &windrect.g_y, &windrect.g_w, &windrect.g_h);*/
  86.  
  87. /*    rc_center(&deskrect, &windrect);*/
  88.  
  89.     if (windrect.g_w>250)    windrect.g_w=250;
  90.     if (windrect.g_h>200)    windrect.g_h=200;
  91.  
  92.     win.handle=wind_create(WINTYPE, windrect.g_x, windrect.g_y, windrect.g_w, windrect.g_h);
  93.     if (win.handle>=0)
  94.         {
  95.         wind_title(win.handle, title);
  96.         wind_open(win.handle, windrect.g_x, windrect.g_y, windrect.g_w, windrect.g_h);
  97.         }
  98.  
  99.     win.b_rect=windrect;
  100.  
  101.     wind_calc(WC_WORK, WINTYPE, win.b_rect.g_x,  win.b_rect.g_y,  win.b_rect.g_w,  win.b_rect.g_h,
  102.                    &win.w_rect.g_x, &win.w_rect.g_y, &win.w_rect.g_w, &win.w_rect.g_h);
  103.     }
  104.  
  105. void open_win(void)
  106.     {
  107.     wind_open(win.handle, win.b_rect.g_x, win.b_rect.g_y, win.b_rect.g_w, win.b_rect.g_h);
  108.     }
  109.  
  110. void close_win(void)
  111.     {
  112.     wind_close(win.handle);
  113.     }
  114.  
  115. void delete_win(void)
  116.     {
  117.     wind_delete(win.handle);
  118.     }
  119.  
  120. short do_menu(short menu_item)
  121.     {
  122.     switch (menu_item)
  123.         {
  124.         case MAbout:
  125.             dialog(about_ptr, 0);
  126.             break;
  127.  
  128.         case MFOpen:
  129.             open=0x01;
  130.             break;
  131.  
  132.         case MFQuit:
  133.             endmainloop=TRUE;
  134.             break;
  135.  
  136.         case M_HELP:
  137.             dialog(help_ptr, 0);
  138.  
  139.         }
  140.  
  141.     /* Christoper Hewett == Mr. Belvedere */
  142.  
  143.     return (endmainloop);
  144.     }
  145.  
  146. short dialog(OBJECT *obj, short edit)
  147.     {
  148.     GRECT rect;
  149.     short exit;
  150.  
  151.     if (edit != 0)
  152.         {
  153.             empty_edits(obj,edit);
  154.         }
  155.  
  156.     if ((edit == city)&&(city_tla!=NULL))
  157.         {
  158.             set_tedinfo(obj,edit,city_tla);
  159.         }
  160.  
  161.  
  162.     form_center(obj, &rect.g_x, &rect.g_y, &rect.g_w, &rect.g_h);
  163.     form_dial(FMD_START, 0, 0, 0, 0, rect.g_x, rect.g_y, rect.g_w, rect.g_h);
  164.     form_dial(FMD_GROW, rect.g_x+rect.g_w/2, rect.g_y+rect.g_h/2, 0, 0, rect.g_x, rect.g_y, rect.g_w, rect.g_h);
  165.  
  166.     objc_draw(obj, ROOT, MAX_DEPTH, rect.g_x, rect.g_y, rect.g_w, rect.g_h);
  167.     exit=form_do(obj, edit);
  168.  
  169.     form_dial(FMD_SHRINK, rect.g_x+rect.g_w/2, rect.g_y+rect.g_h/2, 0, 0, rect.g_x, rect.g_y, rect.g_w, rect.g_h);
  170.     form_dial(FMD_FINISH, 0, 0, 0, 0, rect.g_x, rect.g_y, rect.g_w, rect.g_h);
  171.     obj[exit].ob_state&=~SELECTED;
  172.  
  173.     return (exit);
  174.     }
  175.  
  176. void set_button(OBJECT *tree, short parent, short button)
  177. {
  178.     short b;
  179.     
  180.     for (b=tree[parent].ob_head; b!=parent; b=tree[b].ob_next)
  181.         if (b==button)
  182.             tree[b].ob_state|=SELECTED;
  183.         else
  184.             tree[b].ob_state&=~SELECTED;
  185. }
  186.  
  187. short get_button(OBJECT *tree, short parent)
  188. {
  189.     short b;
  190.  
  191.     b=tree[parent].ob_head;
  192.     for (; b!=parent && !(tree[b].ob_state&SELECTED); b=tree[b].ob_next)
  193.         ;
  194.  
  195.     return b;
  196. }
  197.  
  198. void
  199. empty_edits(OBJECT *tree, int object)
  200. {
  201.     set_tedinfo(tree,object,""); 
  202. }
  203.  
  204. /*
  205.  * copy a string into a TEDINFO structure.
  206.  */
  207. void set_tedinfo(OBJECT *tree,int obj,char *source)
  208. {
  209.     char *dest;
  210.     
  211.     dest=((TEDINFO *)tree[obj].ob_spec)->te_ptext;
  212.     strcpy(dest,source);
  213. }
  214.